//
//  WaitReturnCell.m
//  TengyunStation
//
//  Created by Johnny on 15/9/8.
//  Copyright (c) 2015年 xingrong. All rights reserved.
//

#import "WaitReturnCell.h"
#import "WaitReturnExpress.h"
#import "UIImageView+WebCache.h"
#import "TSHeader.h"

@implementation WaitReturnCell

- (void)awakeFromNib {
    // Initialization code
    _bgView.layer.borderWidth = 0.5;
    _bgView.layer.borderColor = LineColor.CGColor;
    _showdayLabel.layer.cornerRadius = 8;
    _expressLogoImageView.layer.cornerRadius = 4;
    _expressLogoImageView.clipsToBounds = YES;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)reloadWaitReturnCell:(WaitReturnExpress *)express {
    _companyNameLabel.text = express.expressCompanyName;
    _expressIdLabel.text = express.expressId;
    _telephoneLabel.text = express.telephone;
    NSString *companyUrl = [express.expressCompanyLogo stringByReplacingOccurrencesOfString:@"\\" withString:@"/"];
    NSURL *logoUrl = [NSURL URLWithString:companyUrl];
    [_expressLogoImageView sd_setImageWithURL:logoUrl placeholderImage:[UIImage imageNamed:@"yijskd_logo_bg"]];
    if (express.address.length > 0) {
        _positionLabel.attributedText = [self setPositionDefaultString:express.position AttributedStiring:express.address];
    } else {
        _positionLabel.text = express.position;
    }
    _receiveTimeLabel.text = express.receiveTime;
    _showdayLabel.text = express.showDay;
    _showdayLabel.hidden = NO;
    if ([express.showDay isEqualToString:@"今天"]) {
        _showdayLabel.backgroundColor = UIColorFromRGB(0xf49f24);
    } else if ([express.showDay isEqualToString:@"昨天"]) {
        _showdayLabel.backgroundColor = UIColorFromRGB(0xf47624);
    } else if ([express.showDay isEqualToString:@"前天"]) {
        _showdayLabel.backgroundColor = UIColorFromRGB(0xf34a24);
    } else {
        _showdayLabel.hidden = YES;
    }
}

- (NSAttributedString *)setPositionDefaultString:(NSString *)defaultString AttributedStiring:(NSString *)attrString {
    NSString *string = [NSString stringWithFormat:@"%@ / %@",defaultString,attrString];
    NSRange range = [string rangeOfString:defaultString];
    NSMutableAttributedString *attriString = [[NSMutableAttributedString alloc] initWithString:string];
    [attriString addAttribute:NSForegroundColorAttributeName value:AssistTextColor range:range];
    return attriString;
}

@end
